package com.CollectionJiHe.DouDiZhu;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Room {
    public List<Card>allCards=new ArrayList<>();
    public void passCard(){
        Collections.shuffle(allCards);
        System.out.println("打乱后是"+allCards);
        List<Card>DiJia=new ArrayList<>();
        List<Card>GaiYa=new ArrayList<>();
        List<Card>DaiNa=new ArrayList<>();
        for (int i = 0; i < allCards.size()-3; i++) {
            Card c=allCards.get(i);
            if(i%3==0){
                DiJia.add(c);
            }
            if(i%3==1){
                GaiYa.add(c);
            }
            if(i%3==2){
                DaiNa.add(c);
            }

        }
        orderCard(DiJia);
        orderCard(GaiYa);
        orderCard(DaiNa);
        System.out.println("迪迦"+DiJia);
        System.out.println("盖亚"+GaiYa);
        System.out.println("戴拿"+DaiNa);
        List<Card>lastThreeCards=allCards.subList(allCards.size()-3,allCards.size());
        System.out.println("底牌"+lastThreeCards);
        System.out.println("地主是迪迦");
        DiJia.addAll(lastThreeCards);
        orderCard(DaiNa);
        System.out.println("迪迦的牌是"+DiJia);

    }

    public Room() {
        String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        int size=0;
        String[]colors={"♠","♥","♣","♦"};
        for (String number : numbers) {
            size++;
            for (String color : colors) {
                Card c=new Card(number,color,size);
                allCards.add(c);
            }
        }
        Card c2=new Card("","小鬼",++size);
        Card c3=new Card("","大鬼",++size);
        Collections.addAll(allCards,c2,c3);
        System.out.println("新牌是"+allCards);


    }

    public void orderCard(List<Card> cards) {
        Collections.sort(cards, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getSize()-o2.getSize();
            }
        });

    }
}
